let flex = {

	//方向flex-direction:row;
	KEYDIR: 'flex-direction',
	DIRROW: 'row', //行 左到右  默认
	DIRROWR: 'row-reverse', // 右到左
	DIRCOLUMN: 'column', //列 上到下
	DIRCOLUMNR: 'column-reverse', //下到上

	//排列方式 flex-wrap: nowrap;
	KEYWRAP: 'flex-wrap',
	WRAP: 'wrap', //单行
	NOWRAP: 'nowrap', //多行

	KEYACONTENT: 'align-content', //内容
	KEYAITEMS: 'align-items', //子项
	KEYJCONTENT: 'justify-content', //

	START: 'flex-start', //flex-start
	END: 'flex-end', //flex-end
	CENTER: 'center', //center
	BETWEEN: 'space-between', //  //之间
	AROUND: 'space-around', // //周围均分
	BASELINE: 'baseline',
	STRETCH: 'stretch', //拉伸
	EVENLY: 'space-evenly'

};

function hItem(sid, k, childs) {
	return {
		sid: sid,
		k: k,
		child: childs
	}
}
let dir = hItem('dir', flex.KEYDIR,
	[flex.DIRROW, flex.DIRROWR,
		flex.DIRCOLUMN, flex.DIRCOLUMNR
	]);

let wrap = hItem('wrap', flex.KEYWRAP, [
	flex.WRAP, flex.NOWRAP
]);

let acontent = hItem('acontent', flex.KEYACONTENT, [
	flex.START, flex.END, flex.CENTER, flex.AROUND,
	flex.BETWEEN, flex.STRETCH
]);
let jcontent = hItem('jcontent', flex.KEYJCONTENT, [
	flex.START, flex.END, flex.CENTER, flex.AROUND,
	flex.BETWEEN, flex.EVENLY
]);

let items = hItem('items', flex.KEYAITEMS, [
	flex.START, flex.END, flex.CENTER,
	flex.STRETCH, flex.BASELINE
]);

export const TypeFlex = flex;
export const FlexGroup = [dir, wrap, acontent, jcontent, items];

export const flexValue = {
	dir: [flex.DIRROW],
	wrap: [],
	acontent: [],
	jcontent: [],
	items: []
};
const hFlexV = (d) => {
	if (d.length > 1) {
		d.shift(); //移除第一个
	}
}
export function hValueCheck(fvalue) {
	let v = fvalue;
	if (!v) {
		return null;
	}
	hFlexV(v.dir);
	hFlexV(v.wrap);
	hFlexV(v.acontent);
	hFlexV(v.jcontent);
	hFlexV(v.items);
}
export function hDisplayFlex(dom, fv) {
	if (!dom) {
		return;
	}
	let style = dom.style;
	if (fv) {
		style.setProperty("display", 'flex');

		if (fv.dir.length > 0) {
			style.setProperty(flex.KEYDIR, fv.dir[0]);
		} else {
			style.removeProperty(flex.KEYDIR);
		}

		if (fv.wrap.length > 0) {
			style.setProperty(flex.KEYWRAP, fv.wrap[0]);
		} else {
			style.removeProperty(flex.KEYWRAP);
		}

		if (fv.acontent.length > 0) {
			style.setProperty(flex.KEYACONTENT, fv.acontent[0]);
		} else {
			style.removeProperty(flex.KEYACONTENT);
		}

		if (fv.jcontent.length > 0) {
			style.setProperty(flex.KEYJCONTENT, fv.jcontent[0]);
		} else {
			style.removeProperty(flex.KEYJCONTENT);
		}

		if (fv.items.length > 0) {
			style.setProperty(flex.KEYAITEMS, fv.items[0]);
		} else {
			style.removeProperty(flex.KEYAITEMS);
		}
	} else {
		style.removeProperty("display");
		style.removeProperty(flex.KEYDIR);
		style.removeProperty(flex.KEYWRAP);
		style.removeProperty(flex.KEYACONTENT);
		style.removeProperty(flex.KEYJCONTENT);
		style.removeProperty(flex.KEYAITEMS);
	}
}
